/* 公共js代码 包含问卷添加存储、日期等 */
/* 问卷包括id用于唯一标识每一个问卷、title标题、time保存或发布时间、status状态、questions[]包括问卷的每一个问题 */
/* 题目question包括order表示题目的顺序、type题目类型、questionTitle题目名称、option选项、text文本题目、check是否必填、answer[]每一个选项选择次数、answertext文本题目回答 */

//定义初始问卷列表
var Arr = 
    [
        {
            "id": "1",
            "title": "过期问卷测试",
            "time": "2022-12-25",
            "status": "未发布",
            "questions": [
                {
                    "order": "1",
                    "type": "单选题",
                    "questionTitle": "创建时间",
                    "optionCount": 2,
                    "options": [
                        "12.25",
                        "12.26"
                    ],
                    "text": "",
                    "check": "",
                    "answer": [
                        1,
                        3,
                        0,
                        0
                    ],
                    "answertext": 0
                },
                {
                    "order": "2",
                    "type": "多选题",
                    "questionTitle": "过期测试",
                    "optionCount": 4,
                    "options": [
                        "过期1天",
                        "过期2天",
                        "过期3天",
                        "过期4天"
                    ],
                    "text": "",
                    "check": "",
                    "answer": [
                        4,
                        6,
                        2,
                        8
                    ],
                    "answertext": 0
                }
            ]
        },
        {
            "id": "2",
            "title": "保存问卷测试",
            "time": "2023-02-06",
            "status": "未发布",
            "questions": [
                {
                    "order": "1",
                    "type": "单选题",
                    "questionTitle": "喜欢前端吗",
                    "optionCount": 2,
                    "options": [
                        "很喜欢",
                        "非常喜欢"
                    ],
                    "text": "",
                    "check": "",
                    "answer": [
                        0,
                        0,
                        0,
                        0
                    ],
                    "answertext": 0
                },
                {
                    "order": "2",
                    "type": "多选题",
                    "questionTitle": "作业做了多久",
                    "optionCount": 4,
                    "options": [
                        "一个星期",
                        "两个星期以上",
                        "一年",
                        "半天"
                    ],
                    "text": "",
                    "check": "",
                    "answer": [
                        0,
                        0,
                        0,
                        0
                    ],
                    "answertext": 0
                },
                {
                    "order": "3",
                    "type": "文本题",
                    "questionTitle": "说出为什么最喜欢的事是学习？",
                    "optionCount": 0,
                    "options": [],
                    "text": "？？",
                    "check": false,
                    "answer": [
                        0,
                        0,
                        0,
                        0
                    ],
                    "answertext": 0
                }
            ]
        },
        {
            "id": "5",
            "title": "发布问卷测试",
            "time": "2023-02-08",
            "status": "发布中",
            "questions": [
                {
                    "order": "1",
                    "type": "单选题",
                    "questionTitle": "喜欢前端吗",
                    "optionCount": 2,
                    "options": [
                        "很喜欢",
                        "非常喜欢"
                    ],
                    "text": "",
                    "check": "",
                    "answer": [
                        1,
                        2,
                        0,
                        0
                    ],
                    "answertext": 0
                },
                {
                    "order": "2",
                    "type": "多选题",
                    "questionTitle": "喜欢什么前端技术有？",
                    "optionCount": 4,
                    "options": [
                        "HTML",
                        "CSS",
                        "JS",
                        "VUE"
                    ],
                    "text": "",
                    "check": "",
                    "answer": [
                        2,
                        3,
                        3,
                        1
                    ],
                    "answertext": 0
                },
                {
                    "order": "3",
                    "type": "文本题",
                    "questionTitle": "说出为什么最喜欢的事是学习？",
                    "optionCount": 0,
                    "options": [],
                    "text": "说出你的原因",
                    "check": false,
                    "answer": [
                        0,
                        0,
                        0,
                        0
                    ],
                    "answertext": 3
                }
            ]
        }

]
var arr = function(id,title,time,status,questions){
    this.id=id
    this.title=title
    this.time=time
    this.status=status
    this.questions=questions
}
var question = function(order,type,questionTitle,optionCount,options,text,check,answer,answertext){
    this.order=order
    this.type=type
    this.questionTitle=questionTitle
    this.optionCount=optionCount
    this.options=options
    this.text=text
    this.check=check
    this.answer=answer
    this.answertext=answertext
}
// var option = function(count,titles){
//     this.count=count
//     this.titles=titles
// }
// 问卷列表添加方法
var add = function (a){
    Arr[Arr.length]=a
}

// 如果已经存储到本地，即用存储到本地的数据
if(localStorage.getItem("ArrText")){
    Arr=JSON.parse(localStorage.getItem("ArrText"))
}

// 日期框默认时间方法
function completeDate(value) {
    return value < 10 ? "0"+value:value;
}
// 日期方法
var getNowFormatDay = function(nowDate) {
    var char = "-";
    if(nowDate == null){
        nowDate = new Date();
    }
    var day = nowDate.getDate();
    var month = nowDate.getMonth() + 1;//注意月份需要+1
    var year = nowDate.getFullYear();
    //补全0，并拼接
    return year + char + completeDate(month) + char +completeDate(day);
}

const baskMa = document.getElementsByClassName("questionManage")[0]
baskMa.onclick = function(){
    localStorage.removeItem("look-id");
    localStorage.removeItem("edit-id")
    localStorage.removeItem("write-id")
    str="../index.html"
    window.location.href = str
}